package mementoPattern;


import org.junit.Test;

/**
 * @program: course
 * @author: lsn
 * @create: 2024-05-18 16:08
 * @description: 备忘录模式测试类
 */
public class ApiTest {

    @Test
    public void test() {
        Originator originator = new Originator();
        CareTaker careTaker = new CareTaker();
        originator.setState("山西");
        careTaker.add(originator.saveStateToMemento());
        originator.setState("山西农业大学");
        careTaker.add(originator.saveStateToMemento());
        originator.setState("山西农业大学软件学院");
        careTaker.add(originator.saveStateToMemento());
        originator.setState("山西农业大学软件学院软件工程专业");
        System.out.println("Current State: " + originator.getState());
        originator.getStateFromMemento(careTaker.get(0));
        System.out.println("First saved State: " + originator.getState());
        originator.getStateFromMemento(careTaker.get(1));
        System.out.println("Second saved State: " + originator.getState());
        originator.getStateFromMemento(careTaker.get(2));
        System.out.println("Third saved State: " + originator.getState());
    }

    @Test
    public void test1() {
        Originator originator = new Originator();
        CareTaker careTaker = new CareTaker();
        originator.setState("山西");
        originator.setState("山西农业大学");
        careTaker.add(originator.saveStateToMemento());
        originator.setState("山西农业大学软件学院");
        careTaker.add(originator.saveStateToMemento());
        originator.setState("山西农业大学软件学院软件工程专业");

        System.out.println("Current State: " + originator.getState());
        originator.getStateFromMemento(careTaker.get(0));
        System.out.println("First saved State: " + originator.getState());
        originator.getStateFromMemento(careTaker.get(1));
        System.out.println("Second saved State: " + originator.getState());

    }
}

